import {
	DashboardActionType,
	ICtrlEvent,
	IDashboardAbility,
	IDashboardControllerParams,
	IDashboardModel,
	IDashboardStore,
	IParam,
} from '@/core';
import { QXEvent } from 'qx-util';
import {
	getCtrlClassNames,
	useCtrlAction,
	useCtrlBasic,
	handleCtrlDestroy,
	handleCtrlInit,
	handleCtrlAction,
	useCtrlControllerParams,
	useCtrlProps,
} from '../use-ctrl';

/**
 * 数据看板输入参数
 *
 * @export
 * @return {*}
 */
export function useDashboardProps() {
	return {
		...useCtrlProps(),
		openView: Function,
		newView: Function,
		noPadding: {
			type: Boolean,
			default: false,
		},
	};
}

/**
 * 数据看板基础参数
 *
 * @export
 * @param {IDashboardModel} model
 * @param {IParam} props
 * @return {*}
 */
export function useDashboardBasic(model: IDashboardModel, props: IParam) {
	const getClassNames = (props: IParam) => {
		const classNames = getCtrlClassNames(model, props);
		Object.assign(classNames, {
			[`app-control-dashboard`]: true,
		});
		return classNames;
	};
	return {
		...useCtrlBasic(model, props),
		getClassNames,
		handleCtrlDestroy,
		handleCtrlInit,
		handleCtrlAction,
	};
}

/**
 * 数据看板部件行为
 *
 * @export
 */
export function useDashboardAction(controller: any) {
	return {
		...useCtrlAction(controller),
	};
}

/**
 * 数据看板部件控制器
 *
 * @export
 */
export function useDashboardControllerParams<
	S extends IDashboardStore,
	M extends IDashboardModel
>(
	model: M,
	props: any,
	evt: QXEvent<ICtrlEvent<DashboardActionType, IDashboardAbility>>,
	otherParams: IParam = {}
): IDashboardControllerParams<DashboardActionType, IDashboardAbility> {
	return {
		...useCtrlControllerParams<S, M>(model, props, evt, otherParams),
		openView: props.openView,
		newView: props.newView,
	};
}
